import React from 'react'
import { useHistory  } from 'react-router-dom'
import "./index.scss"

const manageList = {
    "ADMIN": "董事长",
    "GM": "副总",
    "CHAIRMAN": "总监",
    "MANAGE": "经理",
    "SP": "区域经理",
    "STAFF": "店长"
}

const Nav = props => {

    let history = useHistory()

    const onBackToLastPage = () => {
        history.push(props.backUrl)
    }

    const onLogOut = () => {
        localStorage.clear();
        history.push("/")
    }

    return (
        <div className="header">
            <div className="left" onClick={onBackToLastPage}>{props.backUrl=="/changePas" ? "修改密码" : "返回"}</div>
            <div>欢迎您，{localStorage.getItem("userName")}{manageList[localStorage.getItem('role')]}</div>
            <div className="right" onClick={onLogOut}>退出登录</div>
        </div>
    )
}

export default Nav;